"""
ASGI config for BroadviewCoss project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from django.urls import path

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BroadviewCoss.settings')
django_application = get_asgi_application()  # 必须优先初始化

from .consumers import SSHConsumer, GuacamoleConsumer  # 导入你的 WebSocket 消费者

application = ProtocolTypeRouter({
    "http": django_application,
    "websocket": AuthMiddlewareStack(
        URLRouter([
            path("ws/<group_name>", SSHConsumer.as_asgi()),  # WebSocket 路由
            path("ws_rdp/<group_name>/<host_id>", GuacamoleConsumer.as_asgi()),
        ])
    ),
})
